<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/limh/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/limh/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/limh/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/limh/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/limh/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/limh/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/limh/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="教程,">










<meta name="description" content="本节提供几个利用协处理器进行编程的例子，从这些例子可看出使用协处理器指令编程的方法和技巧。 例11.8 已知L=4.0，F按每次递增10.0的幅度从10.0增加到1000.0，试按公式Y＝2πFL，计算出100个Y值，并把它们存入数组RES中。 解： 1234567891011121314151617181920212223242526.MODEL        SMALL.386.387.DAT">
<meta name="keywords" content="教程">
<meta property="og:type" content="article">
<meta property="og:title" content="11.4 协处理器的编程举例">
<meta property="og:url" content="https://tdnr.gitee.io/limh/2015/04/01/asm54/index.html">
<meta property="og:site_name" content="土逗牛肉">
<meta property="og:description" content="本节提供几个利用协处理器进行编程的例子，从这些例子可看出使用协处理器指令编程的方法和技巧。 例11.8 已知L=4.0，F按每次递增10.0的幅度从10.0增加到1000.0，试按公式Y＝2πFL，计算出100个Y值，并把它们存入数组RES中。 解： 1234567891011121314151617181920212223242526.MODEL        SMALL.386.387.DAT">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-01-23T03:22:26.321Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="11.4 协处理器的编程举例">
<meta name="twitter:description" content="本节提供几个利用协处理器进行编程的例子，从这些例子可看出使用协处理器指令编程的方法和技巧。 例11.8 已知L=4.0，F按每次递增10.0的幅度从10.0增加到1000.0，试按公式Y＝2πFL，计算出100个Y值，并把它们存入数组RES中。 解： 1234567891011121314151617181920212223242526.MODEL        SMALL.386.387.DAT">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/limh/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tdnr.gitee.io/limh/2015/04/01/asm54/">





  <title>11.4 协处理器的编程举例 | 土逗牛肉</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans ">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/limh/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">土逗牛肉</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/limh/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/limh/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/limh/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/limh/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/limh/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tdnr.gitee.io/limh/limh/2015/04/01/asm54/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="土逗牛肉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/limh/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="土逗牛肉">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">11.4 协处理器的编程举例</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-04-01T20:36:19+08:00">
                2015-04-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/limh/categories/汇编教程/" itemprop="url" rel="index">
                    <span itemprop="name">汇编教程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本节提供几个利用协处理器进行编程的例子，从这些例子可看出使用协处理器指令编程的方法和技巧。</p>
<p><strong>例11.8 已知L=4.0，F按每次递增10.0的幅度从10.0增加到1000.0，试按公式Y＝2πFL，计算出100个Y值，并把它们存入数组RES中。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">.MODEL        SMALL</span><br><span class="line">.386</span><br><span class="line">.387</span><br><span class="line">.DATA</span><br><span class="line">     L DD　4.0</span><br><span class="line">     F DD　1000.0 ;为了便于循环控制，F“从大到小”来计算</span><br><span class="line">     TEN DD　10.0</span><br><span class="line">     Y DD　100 DUP(?)</span><br><span class="line">.CODE</span><br><span class="line"> .STARTUP </span><br><span class="line">              FLDPI                 ;装入π</span><br><span class="line">              FADD      ST, ST(0)   ;自身相加，得到2π</span><br><span class="line">              FMUL      L           ;计算出不变的结果2πL</span><br><span class="line">              MOV       ECX, 100</span><br><span class="line">              MOV       EDI, OFFSET Y-4</span><br><span class="line">      again:</span><br><span class="line">              FLD       F</span><br><span class="line">              FMUL      ST, ST(1)   ;得到一个计算结果2πLF</span><br><span class="line">              FSTP      dword ptr [EDI+4*ECX]   ;保存当前得到结果(从后向前)</span><br><span class="line">              FLD       F</span><br><span class="line">              FSUB      TEN</span><br><span class="line">              FSTP      F           ;F的值变小10.0</span><br><span class="line">              LOOP      again</span><br><span class="line">              FCOMP                 ;先前计算出结果2πL出栈，使之为空</span><br><span class="line">.EXIT         0</span><br><span class="line">              END</span><br></pre></td></tr></table></figure>
<p><strong>例11.9 把内存单元DATA中存放的单精度浮点数以小数的形式显示在屏幕上。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"> .MODEL　SMALL </span><br><span class="line">.386</span><br><span class="line">.387</span><br><span class="line">.DATA</span><br><span class="line">     DATA DD　-1234.75</span><br><span class="line">     STATUS DW　?</span><br><span class="line">     WHOLE DD　?</span><br><span class="line">     FRACT DD　?</span><br><span class="line">.CODE</span><br><span class="line">DISPS PROC　NEAR ;子程序：显示AL中的字符 </span><br><span class="line">              MOV       AH, 6</span><br><span class="line">              MOV       DL, AL</span><br><span class="line">              INT       21H</span><br><span class="line">              RET</span><br><span class="line">       DISPS  ENDP</span><br><span class="line"> .STARTUP </span><br><span class="line">              FSTCW     STATUS      ;以小数形式显示浮点数DATA</span><br><span class="line">              OR        STATUS,0C00H            ;设定截取舍入方式</span><br><span class="line">              FLDCW     STATUS</span><br><span class="line">              FLD       DATA</span><br><span class="line">              FTST</span><br><span class="line">              FSTSW     AX</span><br><span class="line">              AND       AX, 4500H</span><br><span class="line">              CMP       AX, 0100H</span><br><span class="line">              JNZ       Positive</span><br><span class="line">              MOV       AL, ‘-‘</span><br><span class="line">              CALL      DISPS</span><br><span class="line">              FABS</span><br><span class="line">   Positive:</span><br><span class="line">              FLD       ST</span><br><span class="line">              FRNDINT</span><br><span class="line">              FIST      WHOLE       ;保存整数部分</span><br><span class="line">              FSUBR</span><br><span class="line">              FABS</span><br><span class="line">              FSTP      FRACT       ;保存小数部分</span><br><span class="line">              MOV       EAX, WHOLE</span><br><span class="line">              MOV       EBX, 10</span><br><span class="line">              MOV       CX, 0</span><br><span class="line">              PUSH      BX</span><br><span class="line">     Again1:</span><br><span class="line">              MOV       EDX, 0</span><br><span class="line">              DIV       EBX</span><br><span class="line">              ADD       DL, 30H</span><br><span class="line">              PUSH      DX</span><br><span class="line">              INC       CX</span><br><span class="line">              CMP       EAX, 0</span><br><span class="line">              JNZ       Again1</span><br><span class="line">      Disp1:</span><br><span class="line">              POP       AX</span><br><span class="line">              CALL      DISPS       ;显示整数部分</span><br><span class="line">              LOOP      Disp1</span><br><span class="line">              MOV       AL, ‘.’</span><br><span class="line">              CALL      DISPS       ;显示小数点</span><br><span class="line">              MOV       EAX, FRACT</span><br><span class="line">              FSTCW     STATUS</span><br><span class="line">              XOR       STATUS, 0C00H</span><br><span class="line">              FLDCW     STATUS</span><br><span class="line">              FLD       FRACT</span><br><span class="line">              FXTRACT</span><br><span class="line">              FSTP      FRACT</span><br><span class="line">              FABS</span><br><span class="line">              FISTP     WHOLE</span><br><span class="line">              MOV       ECX, WHOLE</span><br><span class="line">              MOV       EAX, FRACT</span><br><span class="line">              SHL       EAX, 9</span><br><span class="line">              RCR       EAX, CL</span><br><span class="line">     Again2:</span><br><span class="line">              MUL       EBX</span><br><span class="line">              PUSH      EAX</span><br><span class="line">              XCHG      EAX, EDX</span><br><span class="line">              ADD       AL, 30H</span><br><span class="line">              CALL      DISPS</span><br><span class="line">              POP       EAX</span><br><span class="line">              CMP       EAX, 0</span><br><span class="line">              JNZ       Again2</span><br><span class="line">.EXIT　0 </span><br><span class="line">              END</span><br></pre></td></tr></table></figure>
<p><strong>例11.10 从键盘上读入一个带小数的数字字符串，然后把它转换成单精度浮点数，并存入内存单元DATA中。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">.MODEL　SMALL </span><br><span class="line">.386</span><br><span class="line">.387</span><br><span class="line">.DATA</span><br><span class="line">DATA DD　0</span><br><span class="line">TEN DD　10.0</span><br><span class="line">TEMP DW　?</span><br><span class="line">SIGN DB　?</span><br><span class="line">.CODE</span><br><span class="line">       GETCH  MACRO                 ;宏GETCH的功能是从键盘读入一个字符</span><br><span class="line">              MOV       AH, 1</span><br><span class="line">              INT       21H</span><br><span class="line">              ENDM</span><br><span class="line">.STARTUP </span><br><span class="line">              FLDZ                  ;ST=0</span><br><span class="line">              GETCH</span><br><span class="line">.IF           AL == ‘+’                   ;判定是否输入正号‘+’</span><br><span class="line">              MOV       SIGN, 0</span><br><span class="line">              GETCH</span><br><span class="line"> </span><br><span class="line">.ENDIF</span><br><span class="line">.IF           AL == ‘-‘</span><br><span class="line">              MOV       SIGN, 1     ;判定是否输入负号‘-’</span><br><span class="line">              GETCH</span><br><span class="line"> </span><br><span class="line">.ENDIF</span><br><span class="line">.REPEAT</span><br><span class="line">              FMUL      TEN</span><br><span class="line">              MOV       AH,0</span><br><span class="line">              SUB       AL, 30H</span><br><span class="line">              MOV       TEMP, AX</span><br><span class="line">              FIADD     TEMP        ;部分数×10.0＋(字符-‘0’)</span><br><span class="line">              GETCH</span><br><span class="line"> </span><br><span class="line">.UNTIL　AL&lt;’0’ || AL&gt;’9’ ;完成整数部分的处理 </span><br><span class="line">              CMP       AL, ‘.’</span><br><span class="line">              JNE       exit</span><br><span class="line">              FLD1                  ;开始处理小数部分</span><br><span class="line">.WHILE1 </span><br><span class="line">              FDIV      TEN</span><br><span class="line">              GETCH</span><br><span class="line"> </span><br><span class="line">.BREAK        .IF AL&lt;’0’ || AL&gt;’9’</span><br><span class="line"> </span><br><span class="line">              MOV       AH, 0</span><br><span class="line">              SUB       AL, 30H</span><br><span class="line">              MOV       TEMP, AX</span><br><span class="line">              FILD      TEMP</span><br><span class="line">              FMUL      ST, ST(1)</span><br><span class="line">              FADD      ST(2), ST</span><br><span class="line">              FCOMP</span><br><span class="line"> </span><br><span class="line">.ENDW</span><br><span class="line">              FCOMP</span><br><span class="line">       exit:</span><br><span class="line">.IF           SIGN == 1                   ;如果是负数，那么需要改变符号</span><br><span class="line">              FCHS</span><br><span class="line"> </span><br><span class="line">.ENDIF</span><br><span class="line">              FSTP      DATA        ;保存最终转换的结果</span><br><span class="line">.EXIT　0 </span><br><span class="line">              END</span><br></pre></td></tr></table></figure>
<p><strong>例11.11 编写一个子程序，求解一元二次方程的根ax2 + bx + c = 0的根。</strong></p>
<p>解：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line">;调用参数：方程的系数a、b和c，R1和R2是指向存放根的指针； </span><br><span class="line"> </span><br><span class="line">;返回参数：返回值存于AX中，其含义：0—有二个根，1—有一个根R1，2—无实根。</span><br><span class="line"> </span><br><span class="line">   Quadratic  PROC      USES DS DI SI, AA:DWORD, BB:DWORD, CC:DWORD, R1:PDWORD, R2:PDWORD</span><br><span class="line"> </span><br><span class="line">              LES       DI, R1      ;(ES:DI) → 1st Root-R1</span><br><span class="line">              LDS       SI, R2      ;(DS:SI) → 2nd Root-R2</span><br><span class="line">              SUB       BX, BX      ;用BX来标识方程有根的情况</span><br><span class="line">              FLD1                  ;栈顶寄存器置1</span><br><span class="line">              FADD      ST, ST      ;栈顶寄存器自加，变成2</span><br><span class="line">              FLD       ST          ;把数值2复制一份到新的栈顶</span><br><span class="line">              FMUL      AA          ;ST = 2A</span><br><span class="line">              FTST                  ;测试ST是否为0，即，考虑A=0的情况</span><br><span class="line">              FSTSW     AX          ;把当前状态寄存器存入AX中</span><br><span class="line">              FWAIT                 ;等待协处理器完成上面操作</span><br><span class="line">              SAHF                  ;AH装入到标志寄存器中</span><br><span class="line">              JNZ       Notzero     ;考虑A = 0的情况</span><br><span class="line">              FLD       CC          ;常数项C进栈</span><br><span class="line">              FCHS                  ;改变栈顶的符号，得到-C</span><br><span class="line">              FLD       BB          ;参数B进栈</span><br><span class="line">              FTST                  ;测试当前栈顶是否为0</span><br><span class="line">              FSTSW     AX</span><br><span class="line">              SAHF</span><br><span class="line">              JZ        EXIT2       ;考虑B = 0的情况</span><br><span class="line">              FDIV                  ;计算出-C/B</span><br><span class="line">              FSTP      dword ptr ES:[DI]       ;得到一个根，并弹出栈顶</span><br><span class="line">              FSTP      ST          ;弹出多余的堆栈数据</span><br><span class="line">              JMP       EXIT1       ;返回，并标识有1个根</span><br><span class="line">    Notzero:</span><br><span class="line">              FMUL      ST(1), ST   ;ST(1) = 4A</span><br><span class="line">              FXCH                  ;ST和ST(1)交换</span><br><span class="line">              FMUL      CC          ;ST = 4AC</span><br><span class="line">              FTST</span><br><span class="line">              FSTSW     AX</span><br><span class="line">              SAHF</span><br><span class="line">              JP        EXIT2       ;如果状态位C2=1，则4AC是无穷大</span><br><span class="line">              FLD       BB          ;装入参数B</span><br><span class="line">              FMUL      ST, ST      ;ST = B2</span><br><span class="line">              FSUBR                 ;ST = B2 - 4AC</span><br><span class="line">              FTST</span><br><span class="line">              FSTSW     AX</span><br><span class="line">              SAHF</span><br><span class="line">              JC        EXIT2       ;如果C0=1，则B2 &lt; 4AC</span><br><span class="line">              JNZ       Tworoot     ;如果C3=1，则B2 = 4AC</span><br><span class="line">              INC       BX          ;标志有1个根</span><br><span class="line">    Tworoot:</span><br><span class="line">              FSQRT                 ;求出B2 - 4AC的平方根</span><br><span class="line">              FLD       BB</span><br><span class="line">              FCHS                  ;得到-B</span><br><span class="line">              FXCH                  ;ST 和ST(1)交换</span><br><span class="line">              FLD       ST          ;栈顶再复制一份</span><br><span class="line">              FADD      ST, ST(2)   ;ST = -B + SQRT(B2 - 4AC)</span><br><span class="line">              FXCH                  ;ST 和ST(1)交换</span><br><span class="line">              FSUBP     ST(2), ST   ;ST = -B - SQRT(B2 - 4AC)</span><br><span class="line">              FDIV      ST, ST(2)   ;得到一个根ST = ST/(2A)</span><br><span class="line">              FSTP      dword ptr ES:[DI]       ;存储第一个根</span><br><span class="line">              FDIVR                 ;得到另一个根ST = ST/(2A)</span><br><span class="line">              FSTP      dword ptr DS:[SI]       ;存储第二个根</span><br><span class="line">              JMP       EXIT</span><br><span class="line">      EXIT2:</span><br><span class="line">              INC       BX          ;无根时的返回出口</span><br><span class="line">              FSTP      ST          ;清除多余的堆栈数据</span><br><span class="line">      EXIT1:</span><br><span class="line">              INC       BX          ;有一个根时的返回出口</span><br><span class="line">              FSTP      ST          ;清除多余的堆栈数据</span><br><span class="line">       EXIT:</span><br><span class="line">              MOV       AX, BX</span><br><span class="line">              RET</span><br><span class="line">   Quadratic  ENDP</span><br><span class="line">              END</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/limh/tags/教程/" rel="tag"># 教程</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/limh/2015/04/01/asm53/" rel="next" title="11.3 协处理器的指令系统">
                <i class="fa fa-chevron-left"></i> 11.3 协处理器的指令系统
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/limh/2015/04/01/asm55/" rel="prev" title="12.1 汇编指令的嵌入">
                12.1 汇编指令的嵌入 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/limh/images/avatar.jpg" alt="土逗牛肉">
            
              <p class="site-author-name" itemprop="name">土逗牛肉</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/limh/archives/">
              
                  <span class="site-state-item-count">255</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/limh/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/limh/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/limhGeek" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:1591054297@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.jianshu.com/u/f73b243e7cc9" target="_blank" title="简书">
                      
                        <i class="fa fa-fw fa-user-circle-o"></i>简书</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">土逗牛肉</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
	var str = GetUrlParam('height');
    if (str === '0'){
		document.getElementById('header').style.display = 'none';
		document.getElementById('comments').style.display = 'none';
		document.getElementById('footer').style.display = 'none';
		document.getElementsByClassName('post-footer').item(0).style.display = 'none'
	}
	
    function GetUrlParam(paraName) {
        var url = document.location.toString();
        var arrObj = url.split("?");

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split("&");
            var arr;

            for (var i = 0; i < arrPara.length; i++) {
                 arr = arrPara[i].split("=");

                if (arr != null && arr[0] === paraName) {
                    return arr[1];
                }
            }
            return "";
        } else {
            return "";
        }
    }
</script>









  












  
  
    <script type="text/javascript" src="/limh/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/limh/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/limh/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/limh/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/limh/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/limh/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/limh/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/limh/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
